package 链表.双指针;


/**
 * https://leetcode.cn/problems/middle-of-the-linked-list/description/
 *
 * * 题解：https://mp.weixin.qq.com/s?__biz=MzAxODQxMDM0Mw==&mid=2247493168&idx=1&sn=b4eeefd0a62af5509785c8859244d264&chksm=9bd41838aca3912ec3ed1db84bded6d3cf8702c98f5274b6da4915923665cb6d1c113fb49f43&scene=178&cur_album_id=2165022824317485057#rd
 */
public class _876_链表的中间结点 {

    public ListNode middleNode(ListNode head) {
        if (head == null || head.next == null) return head;

        ListNode slow = head;
        ListNode fast = head;

        while (fast != null && fast.next != null) {
            slow = slow.next;
            fast = fast.next.next;
        }

        return slow;
    }
}
